package com.kws.tool.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.kws.tool.entity.StandardEntity;
import com.kws.tool.vo.StandardVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author : zhangbenting
 * @date : 2024/10/22 19:06
 * @Version: 1.0
 */
public interface StandardMapper extends BaseMapper<StandardEntity> {

    @Select("<script>" +
            " SELECT " +
            " a.*, " +
            " b.collect_id " +
            " FROM " +
            " `tb_tool_standard` AS a " +
            " LEFT JOIN ( SELECT collect_id, collect_type_id FROM `tb_tool_collect` " +
            " WHERE collect_type = 1 AND user_id = ${userId} ) AS b ON a.id = b.collect_type_id  " +
            " WHERE " +
            " 1 =1 " +
            " <if test='standardName!=null and standardName!=\"\"'>  AND a.standard_name like '%${standardName}%'  </if>  " +
            " <if test='toolType!=null and toolType!=\"\"'>  AND a.tool_type = '${toolType}'  </if>  " +
            " <if test='startTime!=null and startTime!=\"\"'>  AND a.create_time  BETWEEN '${startTime}' and '${endTime}' </if>  " +
            " LIMIT ${ page } , ${ size} " +
            "</script>")
    List<StandardVo> getStandardList(@Param("page") Integer page,
                                     @Param("size") Integer size,
                                     @Param("standardName") String standardName,
                                     @Param("toolType") String toolType,
                                     @Param("userId") Long userId,
                                     @Param("startTime") String startTime,
                                     @Param("endTime") String endTime);

    @Select("<script>" +
            " SELECT " +
            " a.*, " +
            " b.collect_id " +
            " FROM " +
            " (SELECT collect_id, collect_type_id FROM `tb_tool_collect` " +
            " WHERE collect_type = 1 AND user_id = ${userId}) AS b " +
            " LEFT JOIN  " +
            " `tb_tool_standard` AS a ON a.id = b.collect_type_id  " +
            " WHERE " +
            " 1 =1 " +
            " <if test='standardName!=null and standardName!=\"\"'>  AND a.standard_name like '%${standardName}%'  </if>  " +
            " <if test='toolType!=null and toolType!=\"\"'>  AND a.tool_type = '${toolType}'  </if>  " +
            " <if test='startTime!=null and startTime!=\"\"'>  AND a.create_time  BETWEEN '${startTime}' and '${endTime}' </if>  " +
            " LIMIT ${ page } , ${ size} " +
            "</script>")
    List<StandardVo> getUserCollectStandardList(@Param("page") Integer page,
                                     @Param("size") Integer size,
                                     @Param("standardName") String standardName,
                                     @Param("toolType") String toolType,
                                     @Param("userId") Long userId,
                                     @Param("startTime") String startTime,
                                     @Param("endTime") String endTime);
}
